<?php
/**
 * Created by PhpStorm.
 * User: fenfen
 * Date: 2016/10/18
 * Time: 11:38
 */

namespace bc\model;
use bc\ar\MActiveRecord;
use bc\model\wx\User as wxUser;
use bc\model\ecs\UserModel as ecsUser;

class UserModel extends MActiveRecord
{
    public static function tableName()
    {
        return '{{%user}}';
    }

    public function saveDate($openid,$mobile='',$real_name='')
    {
        //入用户总表
        $wxUserModel = new wxUser();
        $whereWxUser =  array('openid'=>$openid);
        $wxUserRow = $wxUserModel->getRow($whereWxUser);
        $whereUser =  array('wxid'=>$openid);
        $ecsUserModel = new ecsUser();
        $ecsUserRow = $ecsUserModel->getRow($whereUser);
        $data['ecs_user_id']=$ecsUserRow['id'];
        $data['wx_user_id']=$wxUserRow['id'];
        $data['create_time']=date('Y-m-d H:i:s', time());
        $data['update_time']=date('Y-m-d H:i:s', time());
        $data['wxid']=$openid;
        $data['mobile']=$mobile;
        $data['real_name']=$real_name;
        $data['is_invalid']=0;
        return  $this->add($data);
    }

    public function getIdCardType($idcard_type)
    {
        $idcardtype=array(
            '1'=>'身份证',
            '2'=>'港澳通行证',
            '3'=>'台湾通行证',
            '4'=>'护照'
        );
        return $idcardtype[$idcard_type];
    }
}